function AIManager::think(%this)
{
   // We could hook into the player's onDestroyed state instead of
   // having to "think", but thinking allows us to consider other
   // things...
   //if (!isObject(%this.player))
   //   %this.player = %this.spawn();
   %this.schedule(500,think);
}

function AIManager::spawn(%this)
{
	if ( (%role=nameToID("MissionGroup/AIDropPoints/Patrol")) >= 0 )
	{
		%count = %role.getCount();
		for ( %i = 0; %i < %count; %i++)
		{
			/*
			%roleClassName = %role.getObject(%i).getClassName();
			%ai = 0;
			// Spawn on the mob on a Path
			if (%roleClassName $= "Path")
				%ai = AIPlayer::spawnOnPath("EnemyPatrol"@%i, EnemyPatrol, "MissionGroup/AIDropPoints/Patrol/" @ %role.getObject(%i).getName());
			// Spawn the mob at a SpawnSphere
			else if (%roleClassName $= "SpawnSphere")
				%ai = AIPlayer::spawn("EnemyPatrol"@%i, EnemyPatrol, %role.getObject(%i).getTransform());
			
			// Let the datablock perform any special initialization it needs to for this AI
			if (%ai)
				%ai.getDataBlock().init(%ai);
			*/
			
			
			// Spawn patroling enemy on a path
			if (%role.getObject(%i).getClassName() $= "Path")
			{
				%pathName = "MissionGroup/AIDropPoints/Patrol/" @ %role.getObject(%i).getName();
				
				if (%ai = AIPlayer::spawnOnPath("EnemyPatrol"@%i, EnemyPatrol, %pathName))
				{
					// Ensure the path existed before we setup the ai anymore
					//%ai.path = %pathName;
					%ai.getDataBlock().init(%ai);
				}
			}
			// Spawn static enemy at spawn sphere marker
			else if (%role.getObject(%i).getClassName() $= "SpawnSphere")
			{
				%ai = AIPlayer::spawn("EnemyPatrol"@%i, EnemyPatrol, %role.getObject(%i).getTransform());
				%ai.getDataBlock().init(%ai);
			}
		}
	}
	
	//if ( (%role=nameToID("MissionGroup/AIDropPoints/Boss")) >= 0 )
	///{
	//}
}

/*
function AIManager::spawnAI(%this, %role, %typeName, %typeDataBlock)
{
	%roleClassName = %role.getObject(%i).getClassName();
	%ai = 0;
	// Spawn on the mob on a Path
	if (%roleClassName $= "Path")
		%ai = AIPlayer::spawnOnPath(%typeName, %typeDataBlock, %pathName);
	// Spawn the mob at a SpawnSphere
	else if (%roleClassName $= "SpawnSphere")
		%ai = AIPlayer::spawn(%typeName, %typeDataBlock, %role.getObject(%i).getTransform());
	
	// Let the datablock perform any special initialization it needs to for this AI
	%ai.getDataBlock().init(%ai);
}
*/

/*
function AIManager::createSoldiers(%this, %mycheckpoint){
  %group = nameToID("Soldiers");
  if (%group != -1) {
    %count = %group.getCount();
    for (%i = 0; %i < %count; %i++){
      %thissoldierspawn = %group.getObject(%i);
      if (%thissoldierspawn.getClassName() $= "SpawnSphere"){

        // Set Default Type as SoldierPrivate
        %datablocktype = "SoldierPrivate";
	     if(%thissoldierspawn.stype $= "SoldierPrivate"){
          %datablocktype = "SoldierPrivate";
        }
        
        // Check the checkpoint
        if(%thissoldierspawn.checkpoint $= "") {
          %thissoldiercheckpoint = 0;
        }else{
          %thissoldiercheckpoint = %thissoldierspawn.checkpoint;
        }

        // Spawn soldier if we need to
        if(%thissoldiercheckpoint >= %mycheckpoint){
           %checkliving = nameToID("SpawnedSoldier" @ %i);
           // If we haven't spawned this soldier before, make him
           if(%checkliving == -1){            
             %checkpath = nameToID(%thissoldierspawn.fpath);
             if(%checkpath != -1){
               %player = SoldierPrivate::spawnOnPath("SpawnedSoldier" @ %i, %thissoldierspawn.fpath, %datablocktype, %thissoldierspawn.getTransform());
             }else{
               %player = SoldierPrivate::spawnOnPath("SpawnedSoldier" @ %i, "", %datablocktype, %thissoldierspawn.getTransform());
             }
           }
        }
      // not a spawn sphere
      }else{
        echo("Warning:  only spawnspheres should be in Soldiers simgroup.");
      }
    }
  // if missing Soldiers group
  }else{
    error("Missing Soldiers group");
  }
}
*/